<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="but">点击</button>
    <div class="he">

    </div>
    <div class="he">

    </div>
    <div class="he">

    </div>
</body>
</html>
<script>
    var but=document.querySelector(".but")
    var he=document.querySelectorAll(".he")
    but.onclick=function(){
        for (let i = 0; i < he.length; i++) {
           he[i].style.backgroundColor="red"
        }
        console.log(1);
    }
</script>
<style>
    .he{
        width: 100px;
        height: 100px;
        background-color: #000;
        margin: 20px;
    }
</style>